package view.room;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import constants.RoomConstants;


public class RoomPanel extends JPanel{
	String[] typeNames  = RoomConstants.TYPE_NAME;
	String[] statusNames = RoomConstants.STATUS_NAME;
	int typeFilter = RoomConstants.ALL_TYPE;
	int statusFilter = RoomConstants.ALL_STATUS;
	
	ButtonGroup typeGroup 	= new ButtonGroup();
	ButtonGroup statusGroup	= new ButtonGroup();
	
	RoomContent roomContent;
	
	public RoomPanel(){
		setLayout(new BorderLayout());		
		roomContent= new RoomContent();
		add(roomContent);
		add(new SideButton(), BorderLayout.EAST);
	}
	
	public class SideButton extends JPanel{
		
		public SideButton(){
			setLayout(new FlowLayout(FlowLayout.LEFT));
			setPreferredSize(new Dimension(120, 20));
			
			JLabel lbType = new JLabel("Type Filter");
			lbType.setPreferredSize(new Dimension(120, 30));
			add(lbType);
			
			for (int i=0; i<typeNames.length; i++){
				JButton btType = new JButton(typeNames[i]);
				typeGroup.add(btType);
				btType.setPreferredSize(new Dimension(120,30));
				btType.addActionListener(new TypeFilterListener(i));
				add(btType);
			}
			
			JLabel lbStatus = new JLabel("Status Filter");
			lbStatus.setPreferredSize(new Dimension(120, 30));
			add(lbStatus);
			
			for (int i=0; i<statusNames.length; i++){
				JButton btStatus = new JButton(statusNames[i]);
				statusGroup.add(btStatus);
				btStatus.setPreferredSize(new Dimension(120,30));
				btStatus.addActionListener(new StatusFilterListener(i));
				add(btStatus);
			}
		}
	}
	
	class TypeFilterListener implements ActionListener{
		private int index;
		public TypeFilterListener(int index){
			this.index = index;
		}
		public void actionPerformed(ActionEvent event){
			typeFilter = index;
			roomContent.filter(typeFilter, statusFilter);
		}
	}
	
	class StatusFilterListener implements ActionListener{
		private int index;
		public StatusFilterListener(int index){
			this.index = index;
		}
		public void actionPerformed(ActionEvent event){
			statusFilter = index;
			roomContent.filter(typeFilter, statusFilter);
		}
	}
}
